import subprocess
import platform

def ping_host(ip_address):
    try:
        if platform.system() == "Windows":
            command = ["ping", "-n", "1", "-w", "1000", ip_address]
        else:
            command = ["ping", "-c", "1", "-W", "1", ip_address]

        output = subprocess.check_output(
            command,
            stderr=subprocess.STDOUT,
            universal_newlines=True
        )
        print(f"成功 ping 通 {ip_address}")
        print(output)
    except subprocess.CalledProcessError as e:
        print(f"无法 ping 通 {ip_address}")
        print(f"退出状态码: {e.returncode}")
        print(f"错误信息: {e.output}")

# 示例：ping 一个 IP 地址
ping_host("192.168.1.1")